package com.battery.system.service.battery.impl;


import com.alibaba.fastjson.JSONObject;
import com.battery.common.core.text.Convert;
import com.battery.system.domain.Prorely;
import com.battery.system.mapper.ProrelyMapper;
import com.battery.system.service.battery.IProrelyService;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * WS设备租借依据表Service业务层处理
 *
 * @author wslr
 * @date 2020-12-27
 */
@Service
public class ProrelyServiceImpl extends BaseServiceImpl<Prorely> implements IProrelyService {


    @Autowired
    private ProrelyMapper prorelyMapper;

    /**
     * 查询WS设备租借依据表
     *
     * @param id WS设备租借依据表ID
     * @return WS设备租借依据表
     */
    @Override
    public Prorely selectProrelyById(Long id) {
        return prorelyMapper.selectProrelyById(id);
    }

    /**
     * 查询WS设备租借依据表列表
     *
     * @param prorely WS设备租借依据表
     * @return WS设备租借依据表
     */
    @Override
    public List<Prorely> selectProrelyList(Prorely prorely) {
        return prorelyMapper.selectProrelyList(prorely);
    }

    /**
     * 新增WS设备租借依据表
     *
     * @param prorely WS设备租借依据表
     * @return 结果
     */
    @Override
    public int insertProrely(Prorely prorely) {
        return prorelyMapper.insertProrely(prorely);
    }

    /**
     * 修改WS设备租借依据表
     *
     * @param prorely WS设备租借依据表
     * @return 结果
     */
    @Override
    public int updateProrely(Prorely prorely) {
        return prorelyMapper.updateProrely(prorely);
    }

    /**
     * 删除WS设备租借依据表对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteProrelyByIds(String ids) {
        return prorelyMapper.deleteProrelyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除WS设备租借依据表信息
     *
     * @param id WS设备租借依据表ID
     * @return 结果
     */
    @Override
    public int deleteProrelyById(Long id) {
        return prorelyMapper.deleteProrelyById(id);
    }

    @Override
    public Prorely selectBySn(String sn) {
        return prorelyMapper.selectBySn(sn);
    }

    /**
     * 根据netty客户端ID获取对应的WS设备租借信息
     *
     * @param ctxId
     * @return
     */
    @Override
    public Prorely selectByCtxId(String ctxId) {
        Example example = new Example(Prorely.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("ctxId", ctxId);
        return prorelyMapper.selectOneByExample(example);
    }


    @Override
    public Prorely selectByIMEI(String imei) {
        Example example = new Example(Prorely.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("imei", imei);
        return prorelyMapper.selectOneByExample(example);
    }


    @Override
    public Prorely selectBySnAndImei(String sn, String imei) {
        Example example = new Example(Prorely.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("imei", imei);
        criteria.andEqualTo("sn", sn);
        return prorelyMapper.selectOneByExample(example);
    }

}
